# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Vagrantfile.aws.mapgraph - Build and Test MapGraph from a Source Branch with an AWS Povider
#
# The launch synopsis for this Vagrantfile:
#
#   % source ./aws.rc
#   % vagrant up
#
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'aws'

Vagrant.require_plugin "vagrant-berkshelf"

Vagrant.configure("2") do |config|

  config.ssh.pty = true
  config.vm.box = "dummy"
  config.vm.hostname = ENV['BIGDATA_HA_HOST_A']

  config.berkshelf.enabled = true

  config.vm.provider :aws do |aws, override|
    aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
    aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
    aws.keypair_name = ENV['AWS_KEYPAIR_NAME']

    aws.ami = "ami-41e7ce28"
    
    #  Amazon Linux AMI with NVIDIA GRID GPU Driver
    #
    #  https://aws.amazon.com/marketplace/pp/B00FYCDDTE?ref=cns_srchrow
    #
    aws.region = ENV['AWS_REGION']
    aws.instance_type = "g2.2xlarge"
    aws.security_groups = [ ENV['AWS_SECURITY_GROUPS'], ENV['AWS_SECURITY_GROUP_PRIVATE'] ]

    aws.tags = {
      'Name' => ENV['BIGDATA_HA_HOST_A']
    }

    override.ssh.username = "ec2-user"
    override.ssh.private_key_path = ENV['AWS_SSH_PRIVATE_KEY']
  end


  config.vm.provision :chef_solo do |chef|
    chef.json = {
		:java => {
			"install_flavor" => "oracle",
			:jdk_version => "7",
			:oracle => { 'accept_oracle_download_terms' => true }
		}
    }

$script = <<SCRIPT
 yum -y update 
 sudo curl -L https://www.opscode.com/chef/install.sh | sudo bash
 yum -y groupinstall "Development Tools"
SCRIPT

    config.vm.provision :shell, inline: $script

    chef.run_list = [
	"recipe[emacs]",
        "recipe[bigdata::mapgraph]"
    ]

  end
end
